﻿using System;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
namespace ud_gSDMS.Cat
{
    public partial class Hosting_package_Edit : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string _id;

        void Page_Load(object sender, EventArgs e)
        {
            //if (!UserCanEditPage() || !UserCanViewPage())
            //{
            //    WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            //}
        
            

            if (!Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    _id = Request["id"];
                    LoadData(_id);
                }
                PopulateLabels();
                PopulateControls();
            }
        }
        private void PopulateLabels()
        {

        }
        private void PopulateControls()
        {
            
        }
        private void LoadData(string id)
        {
            var o = gSDMS_BL.ud_gSDMS_CAT_HOSTING_PACKAGE_Get(id);
            if (o != null)
            {
                hidId.Value = o.CAT_Hosting_ID.ToString();
                txtName.Text = o.Name;
                txtPrice.Text = o.Price.ToString();
                txtSize.Text = o.Size.ToString();
                txtDescription.Text = o.Description;
                chkActive.Checked = o.Active != null ? o.Active.Value : false;
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                gSDMS_BL.ud_gSDMS_CAT_HOSTING_PACKAGE_Upd(string.IsNullOrEmpty(hidId.Value), hidId.Value, txtName.Text,
                                                          txtSize.Text,
                                                          txtPrice.Text, txtDescription.Text, chkActive.Checked);
                lblMes.Text = string.IsNullOrEmpty(_id) ? "Inserted!" : "Updated!";
                Response.Redirect("/gsdmsmodule/cat/hosting_package.aspx");
            }
            catch (Exception ex)
            {
                lblMes.Text = ex.Message;
            }
            lblMes.Visible = true;
        }

        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);

            btnSave.Click+=new EventHandler(btnSave_Click);
            
            //btnFinish.Click += btnFinish_Click;
            SuppressPageMenu();
        }


      
        //void btnFinish_Click(object sender, EventArgs e)
        //{
        //    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        //}

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
        }

        private void LoadPanels()
        {
            Hashtable settings = ModuleSettings.GetModuleSettings(moduleId);
            //config = new ContactFormConfiguration(settings);
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion

        protected void txtSize_TextChanged(object sender, EventArgs e)
        {

        }

        protected void txtName_TextChanged(object sender, EventArgs e)
        {

        }
    }
}